# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# Took this from AUR. Adjusted to our styles, etc.
#
# Old Maintainer: Kyle Keen <keenerd@gmail.com>
# Old Contributor: Christoph Zeiler <archNOSPAM_at_moonblade.dot.org>

pkgname=spectrwm
pkgver=3.7.0.r1.gf6385bc
pkgrel=1
pkgdesc='A minimalistic automatic tiling window manager that tries to stay out of the way.'
arch=('x86_64' 'aarch64')
url="https://github.com/conformal/spectrwm/releases"
license=('custom:ISC')
depends=('dmenu' 'xcb-util' 'xcb-util-wm' 'xcb-util-keysyms' 'libxrandr'
         'libxft' 'libxcursor' 'terminus-font' 'fontconfig' 'libbsd' 'libx11'
         'libxcb')
replaces=('scrotwm')
makedepends=('git' 'libxt')
optdepends=('scrot: screenshots'
            'xlockmore: great screenlocker')
backup=("etc/$pkgname.conf")
source=("git+https://github.com/conformal/$pkgname.git"
        'LICENSE'
        'baraction.sh' \
        "$pkgname-no-preload")
sha512sums=('SKIP'
            '3c5b14b0d5def44fb89e23c8e87a3bcf316a1613ffdd4dc0a2c94e9bf58628b7a109be1dd1f1b7224b29eb1814b86ffc2e1c3ce53159a19644e9be77c1d48bb7'
            '82e15b2c5dbeef5741f6c8f9149067a1aff9d971b949deff091446418f1f2722ff1eb2b9897b9e38424a8a929bfaa5c23f3136facc4946ecd17f657a9c10149a'
            '051029932b194ade5eaf4d9c2f6ac594d46ce33bff347cac083ef833efac80a8a85ad9eae57419c32f9f87e566a59289c5aa02e33ded9fd26dd889eb08ec5db5')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  git describe --long --tags | sed -E 's/^[^0-9]*//;s/([^-]*-g)/r\1/;s/[-_]/./g'
}

prepare() {
  cd $pkgname

  sed -i 's|\"/usr/local/lib/libswmhack.so\"|\"libswmhack.so\"|' spectrwm.c
  sed -i 's/verbose_layout = false;/verbose_layout = true;/' spectrwm.c
  sed -i 's/# modkey = Mod1/modkey = Mod4/' spectrwm.conf
}

build() {
  cd "$pkgname/linux"

  make PREFIX=/usr SYSCONFDIR=/etc
}

package() {
  cd $pkgname

  cd linux
  make PREFIX=/usr SYSCONFDIR=/etc DESTDIR="$pkgdir" install
  install -Dm 644 "$srcdir/$pkgname/$pkgname.desktop" \
    "$pkgdir/usr/share/xsessions/$pkgname.desktop"

  cd ..
  install -Dm 644 "$pkgname.conf" "$pkgdir/etc/$pkgname.conf"
  install -Dm 755 screenshot.sh "$pkgdir/usr/share/$pkgname/screenshot.sh"

  mkdir -p "$pkgdir/etc/$pkgname"
  cp spectrwm_*.conf "$pkgdir/etc/$pkgname/"

  cd $srcdir
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm 755 baraction.sh "$pkgdir/usr/share/spectrwm/baraction.sh"
  install -Dm 755 "$pkgname-no-preload" "$pkgdir/usr/bin/$pkgname-no-preload"

  # fix this for real in the makefile
  rm "$pkgdir/usr/bin/scrotwm"
  ln -s "/usr/bin/$pkgname" "$pkgdir/usr/bin/scrotwm"
}

